package cn.itsource.basic.base.controller;

import cn.itsource.basic.base.service.ILoginService;
import cn.itsource.basic.utils.AjaxResult;
import cn.itsource.org.domain.dto.LoginDto;
import cn.itsource.org.domain.dto.WxParamDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private ILoginService loginService;

    @RequestMapping("/adminlogin")
    public AjaxResult adminlogin(@RequestBody LoginDto dto){
        try {
            return AjaxResult.me().setResultObj(loginService.adminlogin(dto));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("服务器繁忙请稍候在试");
        }
    }

    @PostMapping("/wechat")
    public AjaxResult wechat(@RequestBody Map<String, String> map){
        try {
            //有两种情况 有账号 让他带着参数直接登录
            //没有账号，让他注册之后直接免密登录
            return loginService.wechat(map);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("服务器繁忙请稍候在试");
        }
    }

    @PostMapping("/wechat/binder")
    public AjaxResult binder(@RequestBody WxParamDto paramDto){
        try {

            return loginService.wechbinderat(paramDto);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("服务器繁忙请稍候在试");
        }
    }
}
